<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%-- <jsp:include page="/WEB-INF/backstage/util.jsp"></jsp:include> --%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%  
	String path = request.getContextPath();  
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>修改员工信息</title>
		<link rel="stylesheet" href="${pageContext.request.contextPath }/js/common/bootstrap/css/bootstrap.min.css">
		<link rel="stylesheet" href="${pageContext.request.contextPath }/js/common/bootstrap/css/bootstrap-theme.min.css">
		<script src="${pageContext.request.contextPath }/js/jquery-3.1.1.min.js"></script>
		<script src="${pageContext.request.contextPath }/js/common/bootstrap/js/bootstrap.min.js"></script>
		<script src="${pageContext.request.contextPath }/js/common/bootstrapvaildator/js/bootstrapValidator.min.js"></script>
		<script src="${pageContext.request.contextPath }/js/common/bootstrapvaildator/js/language/zh_CN.js"></script>
	</head>

	<!-- <body style="margin: 30px;"> -->
	<body>
		<!-- <div class="container"> -->
			<center>
				<form action="" name="myform1" id="myform1" method="post" enctype="multipart/form-data">
				<input type="hidden" name="photo" id="photo" value="${bis_shop_user.photo }">
				        	<table class="table table-bordered">
				        		<tr>
				        			<!-- 用户编号隐藏域 -->
				        			<input type="hidden" name="shop_user_id" id="shop_user_id" value="${bis_shop_user.shop_user_id }"></td>
				        			<td align="right">
				        				<div class="form-group">
											<label for="account">员工账号:</label>
										</div>
				        			</td>
				        			<td>
				        				 <div class="form-group">
										    <input type="text" class="form-control" name="account" id="account" value="${bis_shop_user.account }" readonly="readonly">
										 </div>
				        			</td>
				        			<td align="right">
				        				<div class="form-group">
											<label for="photo">头像：</label>
										</div>
				        			</td>
				        			<td>
				        				<div class="form-group">
										  <img src="/bsc${bis_shop_user.photo }" width="120px" height="100px"/>
										  <input type="file" class="form-control" onchange="PreviewImage(this)" name="pic" id="file" placeholder="">
										  <div id="imgPreview"></div>
										</div>
				        			</td>
				        		</tr>
				        		<tr>
				        			<td align="right">
				        				<div class="form-group">
											<label for="username">姓名：</label>
										</div>
				        			</td>
				        			<td>
				        				<div class="form-group">
										    <input type="text" class="form-control" name="username" id="username" value="${bis_shop_user.username }">
										</div>
				        			</td>
				        			<td align="right">
				        				<div class="form-group">
											<label for="work_number">工号：</label>
										</div>
				        			</td>
				        			<td>
				        				<div class="form-group">
										    <input type="text" class="form-control" name="work_number" id="work_number" value="${bis_shop_user.work_number }">
										</div>
				        			</td>
				        		</tr>
				        		<tr>
				        			<td align="right">
				        				<div class="form-group">
											<label for="sex">性别：</label>
										</div>
				        			</td>
				        			<td>
				        				<div class="form-group">
											<select class="form-control" name="sex" id="sex">
												<option value="1" ${bis_shop_user.sex==1?"selected":"" }>男</option>
												<option value="2" ${bis_shop_user.sex==2?"selected":"" }>女</option>											
												<option value="3" ${bis_shop_user.sex==3?"selected":"" }>保密</option>
											</select>
										</div>
				        			</td>
				        			<td align="right">
				        				<div class="form-group">
											<label for="status">用户状态：</label>
										</div>
				        			</td>
				        			<td>
				        				<div class="form-group">
											<select class="form-control" name="status" id="status">												
												<option value="0" ${bis_shop_user.status==0?"selected":"" }>离职</option>						
												<option value="1" ${bis_shop_user.status==1?"selected":"" }>在职</option>					  
											</select>
										</div>
				        			</td>
				        		</tr>
				        		<tr>
				        			<td align="right">
				        				<div class="form-group">
											<label for="shop_id">店铺名称：</label>
										</div>
				        			</td>
				        			<td>
				        				<div class="form-group">
											<select class="form-control" name="shop_id" id="shop_id">
											  	<option value="" selected="selected"></option>
											  	<c:forEach items="${list2 }" var="list2">
													<option value="${list2.shop_id }" ${list2.shop_id==bis_shop_user.shop_id?"selected":"" }>${list2.shop_name }</option>
												</c:forEach>
											</select>
										</div>
				        			</td>
				        			<td align="right">
				        				<div class="form-group">
											<label for="post_code">职位：</label>
										</div>
				        			</td>
				        			<td>
				        				<div class="form-group">
				        					<select class="form-control" name="post_code" id="post_code">
											  	<option value="" selected="selected"></option>
											  	<c:forEach items="${list3 }" var="list3">
													<option value="${list3.post_code }" ${list3.post_code==bis_shop_user.post_code?"selected":"" }>${list3.post_name }</option>
												</c:forEach>
											</select>
										</div>
				        			</td>
				        		</tr>
				        		<tr>
				        			<td align="right">
				        				<div class="form-group">
											<label for="mobile">手机：</label>
										</div>
				        			</td>
				        			<td>
				        				<div class="form-group">
										    <input type="text" class="form-control" name="mobile" id="mobile" value="${bis_shop_user.mobile }">
										</div>
				        			</td>
				        			<td align="right">
				        				<div class="form-group">
											<label for="idno">身份证：</label>
										</div>
				        			</td>
				        			<td>
				        				<div class="form-group">
										    <input type="text" class="form-control" name="idno" id="idno" value="${bis_shop_user.idno }">
										</div>
				        			</td>
				        		</tr>
				        		<tr>
				        			<td align="right">
				        				<div class="form-group">
											<label for="phone">电话：</label>
										</div>
				        			</td>
				        			<td>
				        				<div class="form-group">
										    <input type="text" class="form-control" name="phone" id="phone" value="${bis_shop_user.phone }">
										</div>
				        			</td>
				        			<td align="right">
				        				<div class="form-group">
											<label for="email">邮箱：</label>
										</div>
				        			</td>
				        			<td>
				        				<div class="form-group">
										    <input type="text" class="form-control" name="email" id="email" value="${bis_shop_user.email }">
										</div>
				        			</td>
				        		</tr>
				        		<tr>
				        			<td align="right">
				        				<div class="form-group">
											<label for="born_date">出生日期：</label>
										</div>
				        			</td>
				        			<td>
				        				<div class="form-group">
										    <input type="date" class="form-control" name="born_date" id="born_date" value="<f:formatDate value='${bis_shop_user.born_date }' pattern='yyyy-MM-dd'/>">
										</div>
				        			</td>
				        			<td align="right">
				        				<div class="form-group">
											<label for="entry_date">入职日期：</label>
										</div>
				        			</td>
				        			<td>
				        				<div class="form-group">
											<input type="date" class="form-control" name="entry_date" id="entry_date" value="<f:formatDate value='${bis_shop_user.entry_date }' pattern='yyyy-MM-dd'/>">
										</div>
				        			</td>
				        		</tr>
				        		<tr>
				        			<td align="right">
				        				<div class="form-group">
											<label for="linkman">紧急联系人：</label>
										</div>
				        			</td>
				        			<td>
				        				<div class="form-group">
										    <input type="text" class="form-control" name="linkman" id="linkman" value="${bis_shop_user.linkman }">
										</div>
				        			</td>
				        			<td align="right">
				        				<div class="form-group">
											<label for="linkphone">紧急联系电话：</label>
										</div>
				        			</td>
				        			<td>
				        				<div class="form-group">
										    <input type="text" class="form-control" name="linkphone" id="linkphone" value="${bis_shop_user.linkphone }">
										</div>
				        			</td>
				        		</tr>
				        		<tr>
				        			<td align="right">
				        				<div class="form-group">
											<label for="address">居住地址：</label>
										</div>
				        			</td>
				        			<td colspan="3">
				        				<div class="form-group">
										    <input type="text" class="form-control" name="address" id="address" value="${bis_shop_user.address }">
										</div>
				        			</td>
				        		</tr>
				        		<tr>
				        			<td align="right">
				        				<div class="form-group">
											<label for="remark">备注：</label>
										</div>
				        			</td>
				        			<td colspan="3">
				        				<textarea class="form-control" rows="3" name="remark" id="remark">${bis_shop_user.remark }</textarea>
				        			</td>
				        		</tr>				        		
				        	</table>
				        	<div class="modal-footer">
								<a href="${pageContext.request.contextPath }/zjj/selectBis_shop_user">
				        			<button type="button" class="btn btn-default" data-dismiss="modal" name="zjjclose" id="zjjclose">关闭</button>
				        		</a>
								<button type="button" class="btn btn-primary" name="zjjpreserve" id="zjjpreserve">保存</button>
							</div>
				        </form>
			</center>
		<!-- </div> -->
	</body>

</html>
<script type="text/javascript">
	function PreviewImage(imgFile) {
		var path = window.URL.createObjectURL(imgFile.files[0]);
		document.getElementById("imgPreview").innerHTML = "<img id='img1' width='120px' height='100px' src='" + path + "'/>";
	}
	
	//开始表单验证
	var form = $('#myform1');
	$(document).ready(function() {
		form.bootstrapValidator({
			message: '输入值不合法',
			feedbackIcons: {
				valid: 'glyphicon glyphicon-ok',
				invalid: 'glyphicon glyphicon-remove',
				validating: 'glyphicon glyphicon-refresh'
			},
			fields: {
				account: {
					message: '员工账号不合法',
					validators: {
						notEmpty: {
							message: '员工账号不能为空'
						},
						stringLength: {
							min: 2,
							max: 16,
							message: '请输入2到16个字符'
						},
						regexp: {
							regexp: /^[0-9a-zA-Z_]{1,}$/,
							message: '员工账号只能由字母、数字、下划线组成'
						}
					}
				},
				username: {
					message: '姓名不合法',
					validators: {
						notEmpty: {
							message: '姓名不能为空'
						},
						stringLength: {
							min: 2,
							max: 30,
							message: '请输入2到30个字符'
						},
						regexp: {
							regexp: /^[a-zA-Z0-9_\. \u4e00-\u9fa5 ]+$/,
							message: '姓名只能由字母、数字、点、下划线和汉字组成 '
						}
					}
				},
				work_number: {
					message: '工号不合法',
					validators: {
						notEmpty: {
							message: '工号不能为空'
						},
						stringLength: {
							min: 2,
							max: 30,
							message: '请输入2到30个字符'
						},
						regexp: {
							regexp: /[1-9]\d*/,
							message: '工号只能由数字组成 '
						}
					}
				},
				password: {
					message: '密码无效',
					validators: {
						notEmpty: {
							message: '密码不能为空'
						},
						stringLength: {
							min: 6,
							max: 30,
							message: '用户名长度必须在6到30之间'
						},
						different: { //不能和员工账户相同
							field: 'account',
							message: '不能和员工账户相同'
						}
					}
				},
				password1: {
					message: '密码无效',
					validators: {
						notEmpty: {
							message: '密码不能为空'
						},
						stringLength: {
							min: 6,
							max: 30,
							message: '用户名长度必须在6到30之间'
						},
						identical: { //相同
							field: 'password',
							message: '两次密码不一致'
						},
						different: { //不能和员工账户相同
							field: 'account',
							message: '不能和员工账户相同'
						}
					}
				},
				shop_id: {
					validators: {
						notEmpty: {
							message: '请选择店铺'
						}
					}
				},
				post_code: {
					validators: {
						notEmpty: {
							message: '请选择职位'
						}
					}
				},
				mobile: {
					validators: {
						notEmpty: {
							message: '手机号不能为空'
						},
						regexp: {
							//regexp: "^([0-9]{11})?$",
							//regexp: /^1[3|5|8|9]{1}[0-9]{9}$/,
							//regexp:/^1[345789]\d{9}$/,
							regexp: "^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\\d{8}$",
							message: '手机号码格式错误'
						}
					}
				},
				idno: {
					validators: {
						notEmpty: {
							message: '身份证不能为空'
						},
						regexp: {
							regexp: /\d{17}[\d|x]|\d{15}/,
							message: '身份证格式错误'
						}
					}
				},
				phone: {
					validators: {
						regexp: {
							regexp: /[0-9-()]{7,18}/,
							message: '电话格式错误'
						}
					}
				},
				email: {
					validators: {
						emailAddress: {
							message: '请输入正确的邮件地址如：123@qq.com'
						}
					}
				},
				entry_date: {
					validators: {
						notEmpty: {
							message: '请选择入职日期'
						}
					}
				},
				linkman: {
					message: '紧急联系人不合法',
					validators: {
						different: {
							field: 'username',
							message: '不能和员工姓名相同'
						},
						stringLength: {
							min: 2,
							max: 30,
							message: '请输入2到30个字符'
						},
						regexp: {
							regexp: /^[a-zA-Z0-9_\. \u4e00-\u9fa5 ]+$/,
							message: '紧急联系人只能由字母、数字、点、下划线和汉字组成 '
						}
					}
				},
				linkphone: {
					validators: {
						different: {
							field: 'phone',
							message: '不能和员工电话相同'
						},
						regexp: {
							regexp: /[0-9-()]{7,18}/,
							message: '紧急联系电话格式错误'
						}
					}
				},
				address: {
					validators: {
						stringLength: { //检测长度 
							min: 4,
							max: 60,
							message: '请输入4到60个字符'
						}
					}
				},
			}
		});
		
		//点击保存按钮进行 表单验证 
		//验证成功 提交表单 刷新界面
		$("#zjjpreserve").click(
			function() {
				console.log("---");
				//进行表单验证
				var bv = form.data('bootstrapValidator');
				bv.validate();
				if(bv.isValid()) {
					console.log("+++");
					if(window.confirm("是否修改该员工~！")) {
						/* $.ajax({
				            type:"POST",
				            url:"${pageContext.request.contextPath }/zjj/updateBis_shop_user",
				            data : $("#myform1").serialize(),
			                success: function (result) {
			                    //由于ajax发送的url到控制层不会进行页面的跳转，因为当请求成功以后，请求依然会回success,所以可以在此再写一遍url进行跳转
			                    window.location.href="${pageContext.request.contextPath }/zjj/selectBis_shop_user";
			                }
				        }); */
						document.forms[0].action="${pageContext.request.contextPath }/zjj/updateBis_shop_user";
				        document.forms[0].submit();
					}
				}
			}		
		);
		
	});
	//表单验证结束
</script>